<?php

namespace app\common\model;

use think\Model;

class Expense extends Model
{
    // 表名
    protected $name = 'expense';

    // 追加属性
    protected $append = [
        'type_text',
        'user_id_text',
        'admin_id_text',
        'createtime_text'
    ];

    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['createtime'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    public function getTypeList()
    {
        return ['0' => __('Type 0'),'1' => __('Type 1')];
    }

    public function getUserList(){
        $model = new \app\common\model\User();
        $data = $model->getUserList();
        return $data;
    }

    public function getAdminList(){
        $adminM = new \app\common\model\Admin();
        $data = $adminM->getList();
        return $data;
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['type'];
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getAdminIdTextAttr($value, $data)
    {
        $value = $value ? $value : $data['admin_id'];
        $list = $this->getAdminList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getUserIdTextAttr($value, $data)
    {
        $value = $value ? $value : $data['user_id'];
        $list = $this->getUserList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
